package com.example.demo.mapper;

import com.example.demo.entity.WorkTable;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Mapper
@Repository(value = "MemberMapper")
public interface MemberMapper {

    @Insert("INSERT INTO work_table1 (\n" +
            "table_code,phone,startTime\n" +
            ")VALUES(\n" +
            "#{tableCode},#{phone},#{startTime}\n" +
            ")")
    void startWorkMemberMain(WorkTable workTable);
    @Insert("INSERT INTO work_table2 (\n" +
            "table_code,phone,start_time,update_time\n" +
            ")VALUES(\n" +
            "#{tableCode},#{phone},#{startTime},#{updateTime}\n" +
            ")")
    void startWorkMemberVice(WorkTable workTable);

    @Update("UPDATE work_table1 SET allTime =  #{allTime}  " +
            "WHERE phone = #{phone}  AND state = 0")
    void endWorkMemberMain(WorkTable workTable);

    @Update("UPDATE work_table2 SET allTime =  #{allTime}  ,update_time = #{updateTime},state = 1 " +
            "WHERE phone = #{phone}  AND state = 0")
    void endWorkMemberVice(WorkTable workTable);



    @Update("UPDATE work_table1 SET allTime =  #{allTime} ,earnMoney = earnMoney+#{earnMoney} " +
            "WHERE phone = #{phone}  AND state = 0")
    void updateMemberWorkMain(WorkTable workTable);

    @Update("UPDATE work_table2 SET allTime = allTime+#{allTime} ,earnMoney = earnMoney+ #{earnMoney} ,update_time = #{updateTime} " +
            "WHERE phone = #{phone}  AND state = 0")
    void updateMemberWorkVice(WorkTable workTable);
    void getWorkMember(WorkTable workTable);
    void judgeWorkMember(String phone);

    @Insert("insert into article(\n"+
                   "phone,amount\n"+
                   ")values(\n"+
                   "#{phone},#{amount}\n"+
                   ")")
    @Options(useGeneratedKeys = false)
    void  save(@Param("phone") String phone, @Param("amount") Integer amount);
}
